<template>
    <div class="wc">
        <!-- <h2>login</h2> -->
        <div class="loginform">
            <el-form :model="form" label-width="100px" :rules="rules" ref="myForm">
                <el-form-item label="用户名" prop="username">
                    <el-input v-model="form.username"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input v-model="form.password"></el-input>
                </el-form-item>
                <p style="width:100%;padding-left:100px;">
                    <!-- <span style="display:inline-block;width:100px"></span> -->
                    <el-button type="primary" style="width:100%;" @click="onSubmit">登录</el-button>
                </p>
            </el-form>
        </div>
    </div>
</template>
<script setup lang="ts">
import {unref,ref,reactive} from 'vue'
import { useRouter, onBeforeRouteUpdate } from "vue-router";
import type formRules from 'element-plus'
const myForm = ref(null)
const router = useRouter();
const form= reactive({
    username:'',
    password:''
})
const onSubmit=()=>{
    const form = unref(myForm)
                try {
                 let res = form.validate()
                 console.log('res',res)
                 if (res){
					 sessionStorage.setItem("token", "123456");
                        router.push('/home') 
                   }   
                } catch (error){
                  alert('error submit!!')
                }    
    
    console.log('onSubmit')
}

const rules = reactive<FormRules>({
    username:[
        { required: true, trigger: 'blur' },
    ],
    password:[
        { required: true, trigger: 'blur', },
    ]
})
</script>
<style scoped lang="scss">
.wc{
    width: 100%;
    height: 100%;
    position: relative;
    background:#CEDCE3;
    
}
.loginform{
    width: 500px;
    height: 300px;
    position: absolute;
    padding: 40px;
    padding-top: 100px;
    left: 50%;
    top: 50%;
    transform: translate(-50%,-50%);
    border-radius: 10px;
    // border: 1px solid #333;
    text-align: center;
    background:#66a9c9;
    // background-image: linear-gradient( 135deg, #3C8CE7 10%, #00EAFF 100%);
    color: #fff;
}
:deep(.el-form-item__label){
    color: #fff;
}
</style>
